<template>
    <div id="qq">
        <div id="aa">
            <div id="zz"><input type="text" placeholder="蔻驰" v-model="str" @input="wordChange"><span @touchstart="back" v-if="iskong">取消</span>
                <router-link :to="'/user/search1/'+str" v-if="!iskong">搜索</router-link>
            </div>
            <div class="qwe"><span class="fa fa-clock-o"></span><span>最近搜索</span></div>
            <p>无搜索历史</p>
            <div class="qwe"><span class="fa fa-thumbs-o-up"></span><span>热门搜索</span></div>
            <div id="ww">
                <ul>
                    <li v-for="l in list">{{l}}</li>
                </ul>
            </div>
            <ul id="search-box" v-show="searchResult.length>0">
                <li v-for="g in searchResult" class="item">
                    {{g.name}}
                </li>
            </ul>
        </div>
    </div>
</template>
<script>
    export default {
        data: function () {
            return {
                list: ["兰蔻", "科颜氏", "阿玛尼", "浪琴", "清仓特惠", "天梭", "蔻驰", "雅诗兰黛", "MCM", "娇兰", "纪梵希", "雷朋", "施华洛世奇"],
                str: "",
                iskong: false,
                data1: [],
                timer:null,
                searchResult:[]
            }
        },
        watch: {
            str: function () {
                if (this.str == "蔻驰") {
                    this.iskong = true
                } else if (this.str == "") {
                    this.iskong = true
                } else {
                    this.iskong = false
                }
            }
        },
        mounted: function () {
            if (this.str == "蔻驰") {
                this.iskong = true
            } else if (this.str == "") {
                this.iskong = true
            } else {
                this.iskong = false
            }
        },
        methods: {
            back: function () {
                history.back();
            },
            wordChange: function () {
                // console.log(123)
                if (this.timer) {
                    clearTimeout(this.timer);
                    this.timer = null;
                }
                this.timer = setTimeout(function () {
                    if (this.str) {
                        var params = {
                            shopname: this.str,
                            size:1
                        }
                        // console.log(params)
                        this.$store.dispatch("requestSearch", params)
                            .then(res => {
                                // console.log(res.data.data)
                                this.searchResult = res.data.data;
                            })
                    } else {
                        this.searchResult = [];
                    }
                    this.timer = null;
                }.bind(this), 700);

            },
        }
    }

</script>

<style scoped>
    ul {
        display: inline-block;
        margin: 0;
        padding: 0;
    }

    li {
        display: inline-block;
        font-size: 14px;
        list-style: none;
        padding: 0 15px;
        background-color: #eee;
        border-radius: 14px;
        /*border: solid 1px black;*/
        margin-right: 15px;
        margin-bottom: 8px;
        color: #333;
    }

    ul li:nth-of-type(2n+1) {
        color: red;
    }

    #qq {
        height: 100vh;
        background-color: #eee;
    }

    #aa {
        background-color: white;
        position: relative;
    }

    #zz {
        padding: 3vw 5vw;
    }

    #zz input {
        width: 75vw;
        height: 9vw;
        background-color: #eee;
        border: none;
    }

    #zz span,
    a {
        padding-left: 4vw;
        font-size: 14px;
        color: #666;
    }

    .qwe {
        font-size: 16px;
        color: #666;
    }

    .qwe span:nth-of-type(1) {
        font-size: 22px;
        color: #bbb;
        padding: 5px 7px 0 10px;
    }

    p {
        padding-left: 10vw;
        font-size: 12px;
        color: black;
        margin-bottom: 10vw;
    }

    #ww {
        width: 87vw;
        margin-left: 10vw;
        /*border: solid 1px black;*/
        margin-top: 20px;
        padding-bottom: 15px;
    }
    #search-box{
        position: absolute;
        background-color: #eee;
        top:40px;
        left: 10px;
        /*border: solid 1px #bbb;*/
    }
</style>